package hook

import "gitee.com/dreamwood/ez/server"

func init() {
	server.AddPreparer("CORS", func(operation *server.Operation) {
		operation.Output.Response.Header().Set("Access-Control-Allow-Origin", "*")
		operation.Output.Response.Header().Set("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token, a-auth-token, Authorization, x-auth-token")
		operation.Output.Response.Header().Set("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
		operation.Output.Response.Header().Set("Access-Control-Allow-Credentials", "true")
		operation.Output.Response.Header().Set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS")

		if operation.Input.Request.Method == "OPTIONS" {
			operation.Stop()
		}

	})
}
